<template>
  <view>
    <uiScroll ref="mescrollRef" @init="mescrollInit" :up="upOption" @up="loadRecommended">
      <homeLession
        v-for="(item, index) in list"
        :key="index"
        :lessionId="item.lessonId"
        :lessonPicPath="item.lessonPicPath"
        :lessonName="item.lessonName"
        :lecturePic="item.lecturePic"
        :lecturerName="item.lecturerName"
        :lessonPrice="item.lessonPrice"
        :clickNum="item.clickNum"
        :subNum="item.subNum"
        :isVipLesson="item.isVipLesson"
        :lessonCheapPrice="item.lessonCheapPrice"
      ></homeLession>
    </uiScroll>
  </view>
</template>

<script>
import uiScroll from "@/components/base/scroll/mescroll-body";
import uiScrollMixins from "@/components/base/scroll/mescroll-mixins.js";
import homeLession from "@/components/business/lession/lession-row.vue";
import { selectLessonByName } from "api/order/lession.js";

import { url } from "@/utils/url.js";

export default {
  name: "searchResult",
  components: {
    uiScroll,
    homeLession
  },
  mixins: [uiScrollMixins],
  data() {
    return {
      // 下拉刷新的常用配置
      downOption: {
        use: false, // 是否启用下拉刷新; 默认true
        auto: false, // 是否在初始化完毕之后自动执行下拉刷新的回调; 默认true
        native: false // 启用系统自带的下拉组件,默认false;仅mescroll-body生效,mescroll-uni无效(native: true, 则需在pages.json中配置"enablePullDownRefresh":true)
      },
      // 上拉加载的常用配置
      upOption: {
        use: true, // 是否启用上拉加载; 默认true
        auto: true, // 是否在初始化完毕之后自动执行上拉加载的回调; 默认true
        textNoMore: "没有更多数据",
        page: {
          num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
          size: 5, // 每页数据的数量,默认10
          totalPage: 1
        },
        empty: {
          tip: "暂无相关数据"
        }
      },
      // 当前页面查询的参数
      searchValue: "",
      list: []
    };
  },
  created() {
    // this.loadRecommended();
  },
  onLoad() {
    const curUrl = url();
    this.searchValue = curUrl.query.val || "";
  },
  mounted() {},
  methods: {
    loadRecommended(page) {
      let pageNum = page.num; // 页码, 默认从1开始
      let pageSize = page.size; // 页长, 默认每页10条
      var params = {
        page: {
          currentPage: page.num,
          pageNumber: pageSize
        },
        lessonName: this.searchValue,
        type: 1
      };
      var _this = this;
      selectLessonByName(params).then(({ respCode, respMsg, result }) => {
        this.isloading = false;
        if (respCode !== "0") {
          // 加载失败
          this.$toast.fail(respMsg);
          return;
        }
        if (page.num == 1) this.list = []; //如果是第一页需手动置空列表
        this.list = this.list.concat(result.list); //追加新数据
        this.mescroll.endByPage(this.list.length, result.page.totalPage);
      });
    },
    onLoadMore() {}
  }
};
</script>

<style scoped lang="scss" src="./index.scss">
</style>
